import request from '@/utils/axios/axios-service.ts'

/**
 * App应用接口
 */
export const appList = (params: any) => request.get('/app/info/list', {params: params})
export const appInfo = (id: number) => request.get('/app/info/info/' + id)
export const appDetail = (params: any) => request.get('/app/info/detail', {params: params})
export const appSaveOrUpdate = (params: any, isCreate: boolean) => request.post(isCreate ? '/app/info/create' : '/app/info/update', params)

export const appVersionList = (params: any) => request.get('/app/version/list', {params: params});
export const appVersionInfo = (id: number) => request.get('/app/version/info/' + id);
export const appVersionUpdate = (params: any) => request.post('/app/version/update', params);
export const appVersionSaveOrUpdate = (params: any, isCreate: boolean) => request.post(isCreate ? '/app/version/create' : '/app/version/update', params)
export const appVersionPublish = (params: any) => request.post('/app/version/publish', params);

export type AppInfo = {
  id: number;
  name: string;
  type: number;
  bundle_id: string;
  icon_url: string;
  store_url?: number;
  description: string;
  enabled: boolean;
  create_by: number;
  create_user: string;
  update_by?: number;
  update_user?: string;
}

export type AppVersion = {
  id: number;
  app_id: number,
  build: number,
  code: string;
  message: string;
  file_size: number;
  download_url: string;
  download_count: number;
  channel_type: string;
  force_update: boolean;
  enabled: boolean;
}

// 默认数据设置
export const defAppInfo: AppInfo = <AppInfo>{id: 0, enabled: true};
export const defAppVersion: AppVersion = <AppVersion>{id: 0, force_update: true, enabled: true};
